local drowningSkill = fk.CreateSkill{
  name = "iberia__drowning_skill",
}

Fk:loadTranslationTable { ["iberia__drowning"] = "水淹七军" }

local I = require "packages/iberia/utility"

drowningSkill:addEffect("cardskill", {
  prompt = "#iberia__drowning_skill",
  can_use = Util.CanUse,
  target_num = 1,
  mod_target_filter = function(self, player, to_select, selected, card, distance_limited)
    return to_select ~= player and #to_select:getCardIds(Player.Equip) > 0
  end,
  target_filter = Util.CardTargetFilter,
  on_effect = function(self, room, effect)
    local from = effect.from
    local to = effect.to
    local all_choices = {"iberia__drowning_throw", "iberia__drowning_damage:" .. from.id}
    local choices = table.clone(all_choices)
    if #to:getCardIds(Player.Equip) == 0 then
      table.remove(choices, 1)
    end
    local choice = room:askToChoice(to, {
      choices = choices,
      all_choices = all_choices,
      skill_name = "iberia__drowning",
      cancelable = false
    })
    if choice == "iberia__drowning_throw" then
      local equips = to:getCardIds(Player.Equip)
      room:throwCard(equips, "iberia__drowning", to, to)
      if I.isRepeller(from) then
        equips = table.filter(equips, function(id) return room:getCardArea(id) == Card.DiscardPile end)
        local card = room:askToChooseCard(from, {
          flag = { card_data = { {"pile_discard", equips } } },
          target = from,
          skill_name = "iberia__drowning"
        })
        room:obtainCard(from, card, true, fk.ReasonJustMove, from, "iberia__drowning")
      end
    else
      room:damage({
        from = from,
        to = to,
        card = effect.card,
        damage = 1,
        damageType = fk.ThunderDamage,
        skillName = "iberia__drowning",
      })
    end
  end
})

return drowningSkill
